package ch.zbw.pra.sysventory.domain.visualisation;

import java.util.ArrayList;
import java.util.List;

import com.thoughtworks.xstream.annotations.XStreamOmitField;

public abstract class AVisuControll implements IVisuControllSubject {
	@XStreamOmitField
	private List<IVisuControllObserver> observerList;

	public AVisuControll() {
		this.observerList = new ArrayList<IVisuControllObserver>();
	}

	public void addObserver(IVisuControllObserver observer) {
		if (observer != null && containObservers(observer)) {
			this.observerList.add(observer);
		}
	}

	public void removeObserver(IVisuControllObserver observer) {
		if (observer != null) {
			this.observerList.remove(observer);
		}
	}

	public void updateObserver() {
		for (IVisuControllObserver obs : this.observerList) {
			obs.update();
		}
	}

	private boolean containObservers(IVisuControllObserver observer) {
		if (this.observerList == null) {
			this.observerList = new ArrayList<IVisuControllObserver>();
		}
		return !this.observerList.contains(observer);
	}
}
